<?php
class NodeModel extends Db
{
    protected $_node = 'w_node';
    /**
     * 获取权限
     * @param int $fid  父类
     * @return array $result
     */
    public function getCategory($fid = NULL)
    {
        if ($fid === NULL) {
            $sql = "SELECT * FROM $this->_node";
        } else {
            $sql = "SELECT * FROM $this->_node WHERE `fid`=$fid";
        }
        $result = $this->fetchAll($sql);
        return $result;
    }
    /**
     * 
     * 获取权限
     * @param string $node
     */
    public function getMemberNode($node)
    {
        $rs = $this->getOne($this->_node, array(
                'node' => $node));
        return $rs;
    }
    /**
     * 添加节点
     * @param array $arr
     */
    public function addCategory($arr)
    {
        $sql = "select `value` from $this->_node order by `id` desc LIMIT 1";
        $id = $this->fetch($sql);
        $value = $id['value'] * 2;
        $arr = array_merge($arr, array(
                'value' => $value));
        $this->add($this->_node, $arr);
    }
    
    /**
     * 
     * 获取节点信息
     * @param string $name
     */
    public function getNodeByNode($node)
    {
        return $this->getOne($this->_node, array(
                'node' => $node));
    }
    
    /**
     * 删除节点
     * @param array $arr
     */
    public function deleteCategory($arr)
    {
        $this->delete($this->_node, $arr);
    }
    /**
     * 节点更名
     * @param array $v
     * @param array $where
     */
    public function renameCategory($v, $where)
    {
        $this->update($this->_node, $v, $where);
    }
    /**
     * 获取指定的节点
     * @param unknown_type $categoryId
     */
    public function getOneCategory($categoryId)
    {
        $sql = "SELECT * FROM $this->_node WHERE id=$categoryId";
        $rs = $this->fetch($sql);
        return $rs;
    }
    /**
     * 节点条数
     * @package array $WHERE
     */
    public function checkCateNum($WHERE)
    {
        return $this->getOne($this->_node, $WHERE);
    }
    /**
     * 添加权限
     * @param array $array 参数
     */
    public function addNode($array)
    {
        $this->add($this->_node, $array);
    }
    /**
     * 获取所有权限
     */
    public function getNodeAll($where = NULL, $key = NULL)
    {
      
        $rs = $this->getAll($this->_node, $where, $key, "sort ASC");
        return $rs;
    }
    /**
     * 返回NodeModel
     * @return NodeModel
     */
    public static function instance()
    {
        return parent::_instance(__CLASS__);
    }
}